package org.linlinjava.litemall.db.util;

import java.time.LocalDateTime;

public class SequenceUtils {

    /**
     * 生成 YYMMDDHHMMSS 的序列
     *
     * @return
     */
    public static long genDateTimeSeq()
    {
        LocalDateTime ld = LocalDateTime.now();
        long year = (ld.getYear() % 1000) * 10000000000L;
        long month = ld.getMonthValue() * 100000000;
        long day = ld.getDayOfMonth() * 1000000;
        long hour = ld.getHour() * 10000;
        long min = ld.getMinute() * 100;
        return year + month + day + hour + min + ld.getSecond();
    }

    /**
     * 自旋到下一秒
     *
     * @param lastTime 上次时间
     * @return yyMMddHHmmss
     */
    public static long tilNextSecond(long lastTime)
    {
        long timestamp = genDateTimeSeq();
        while (timestamp <= lastTime)
        {
            timestamp = genDateTimeSeq();
        }
        return timestamp;
    }

    public static void main(String[] args)
    {
        long l = genDateTimeSeq();
        System.out.println(l);
    }
}
